package main

import (
	"fmt"
	"io/ioutil"
	"net/http"
)

func main() {
	http.HandleFunc("/index", indexHandler)
	http.HandleFunc("/home", homeHandler)
	fmt.Println("监听：127.0.0.1:8000")
	http.ListenAndServe("127.0.0.1:8000", nil)
}

func indexHandler(w http.ResponseWriter, r *http.Request) {
	fmt.Println(r.RemoteAddr, "连接成功")
	// 请求方式：GET POST DELETE PUT UPDATE
	fmt.Println("method:", r.Method)
	// 请求地址
	fmt.Println("url:", r.URL.Path)
	// 请求头
	fmt.Println("header:", r.Header)
	// 请求体
	fmt.Println("body:", r.Body)
	// 回复
	w.Write([]byte("www.liuqingzheng.top"))
}

func homeHandler(w http.ResponseWriter, r *http.Request) {
	buf, _ := ioutil.ReadFile("./home.html")
	w.Write(buf)
}
